﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FreedomERP.Services.Bd.Impl;
using FreedomERP.Models;
using System.Collections;
using FreedomERP.Comm;
using System.Text;
using System.Data.Objects;

namespace FreedomERP.Dao.Bd.Impl
{
    public class BdRoleDaoImpl : IBdRoleDao
    {
        FreedomERPEntities dbEntities = new FreedomERPEntities();

        /*
         * 根据条件获取角色列表
         * 梁建东
         */
        public List<BdRole> QueryRoleListByFOrgunit(string FOrgunitId)
        {
            //where
            List<ObjectParameter> paramList = new List<ObjectParameter>();
            StringBuilder sbWhere = new StringBuilder();
            if (FOrgunitId != null && !FOrgunitId.Equals(""))
            {
                sbWhere.Append("it.FOrgunitId=@FOrgunitId and ");
                ObjectParameter param = new ObjectParameter("FOrgunitId", FOrgunitId);
                paramList.Add(param);
            }
            sbWhere.Append("1=1");

            //order by
            StringBuilder sbOrder = new StringBuilder();
            sbOrder.Append("it.FId asc");

            ObjectParameter[] objParameters = new ObjectParameter[paramList.Count];
            int c = 0;
            foreach (ObjectParameter paramTemp in paramList)
            {
                objParameters[c] = paramTemp;
                c++;
            }

            var query = dbEntities.BdRole.Where(sbWhere.ToString(), objParameters).OrderBy(sbOrder.ToString());

            List<BdRole> list = query.ToList();

            return list;
        }
    }
}